//导入request.js请求工具
import request from '@/utils/request.js'

//提供注册接口的函数
export const adminRegisterService = (registerData) => {
    return request.post('/admin', registerData, {
        headers: {
            'Content-Type': 'application/json',
        },
    });
}

//提供登录接口的函数
export const adminLoginService = async (loginData) => {
    const response = await request.post('/admin/login', loginData);
    const jwtToken = response.data;
    localStorage.setItem('adminJwtToken', jwtToken);
    return response;
}

//上传文件
export const uploadPhotoService = async (formData) => {
    try {
        const response = await request.post('/admin/upload', formData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        });
        return response.data;
    } catch (error) {
        throw new Error('上传照片失败: ' + error.message);
    }
}

//修改管理员数据
export const AdminUpdateService = (userData) => {
    return request.put('/admin', userData)
}

//修改密码
export const UpdatePasswordService = (userData) => {
    return request.put('/admin/password', userData)
}

//发送邮箱验证码
export const sendCodeService = (phone) =>{
    return request.post('/admin/phone', phone, {
        headers: {
            'Content-Type': 'application/json',
        },
    });
}

//重置密码
export const adminForgetPassService =(phone, pass, verify) => {
    console.log(phone, pass, verify)
    return request.put(`/admin/repass?phone=${phone}&pass=${pass}&verify=${verify}`);
}
